<template>
  <div class="hello">
    <el-button type="primary" @click="changeName">Click me</el-button>
    <span style="margin-left:20px;">{{ store.usrInfo.name }}</span>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import mainStore from "../store/main.store";
// import { storeToRefs } from "pinia";

export default defineComponent({
  name: "HelloWorld",
  props: {
    msg: String,
  },
  setup() {
    const store = mainStore();
    // 响应式解构, 直接解构失去响应式
    // const { usrInfo } = storeToRefs(store);
    // console.log(usrInfo);
    // $patch可以批量修改state，对象里键值就是修改对应的键值,没写的则不改
    // store.$patch({})
    const changeName = () => {
      store.changeInfo({ name: "吻别" });
    };
    return {
      store,
      changeName,
    };
  },
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
